﻿using Direct.IDAL.User.Bonus;
using DirectSell.Model.Bonus;
using DirectSell.Model.Query;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Webdiyer.WebControls.Mvc;

namespace DirectSell.DAL.User.Bonus
{
    /// <summary>
    /// 奖金数据访问层
    /// </summary>
    public class BonusRepository:AbsRepository, IBonusRepository
    {
        #region 查奖金列表视图
        /// <summary>
        /// 查奖金列表
        /// </summary>
        /// <returns></returns>
        public async Task <PagedList<MemberBonus>> QueryBonusList(int userid,int PageIndex,int PageSize)
        {
            PageParam model = new PageParam()
            {
                OrderBy = "UserId DESC",
                PageIndex = PageIndex,
                PageSize = PageSize,
                TableName = "view_bonus",
                StrWhere = $"UserId={userid}"
            };
            return await base.PageQuery<MemberBonus>(model);
            //string str = string.Format(" SELECT * FROM view_bonus WHERE UserId={0} ",userid);
            //return base.Query<MemberBonus>(str.ToString()) as IList<MemberBonus>;
        }
        #endregion

        #region 查一条奖金
        /// <summary>
        /// 查一条奖金
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public MemberBonus QueryBonus(int id)
        {
            string str = string.Format(" SELECT * FROM Bouns WHERE Id = {0} ",id);
            return base.Query<MemberBonus>(str.ToString()).FirstOrDefault();
        }
        #endregion

        #region 查总奖金视图
        /// <summary>
        /// 查总奖金视图
        /// </summary>
        /// <param name="usercode"></param>
        /// <returns></returns>
        public MemberBonus QuerySumBonus(string usercode)
        {
            string str = string.Format(" SELECT * FROM view_sumbonus where UserCode='{0}' ", usercode);
            return base.Query<MemberBonus>(str.ToString()).FirstOrDefault();
        }

        #endregion

    }
}
